cmake_minimum_required(VERSION 3.10.2)

project(gait LANGUAGES CXX)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 添加必要的依赖包
find_package(behaviortree_cpp)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)  # 标准消息类型
# find_package(nav2_behavior_tree REQUIRED)
# find_package(nav2_common REQUIRED)
include_directories(
      include
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# Source files
set(BUILD_SOURCE_FILES 
    gait_phase_detect.cpp 
    plugins/action/initial_stage_action.cpp 
    plugins/action/data_prerocess_action.cpp
    plugins/action/find_heel_strike.cpp 
    plugins/action/find_lr_zerocross.cpp
    plugins/action/find_toe_off.cpp 
    utils/load_data.cpp
    # utils/timer_utils.cpp
)





add_executable(${PROJECT_NAME}  ${BUILD_SOURCE_FILES})
add_executable(timer_test  test/timer_test.cpp)
#单独配置插件
add_library(initial_stage_action_bt_node SHARED plugins/action/initial_stage_action.cpp )
# list(APPEND plugin_libs initial_stage_action_bt_node)
# BT_PLUGIN_EXPORT ：定义的宏名称，通常用于控制符号的导出行为（如动态库的接口导出）。用于在CPP中配合#ifdef使用
target_compile_definitions(initial_stage_action_bt_node PRIVATE  BT_PLUGIN_EXPORT )
# 修改目标属性，将目标的PREFIX 属性设置为空字符串，即移除默认的库名前缀lib，remove the "lib" prefix. Name of the file will be test_plugin_action.so
set_target_properties(initial_stage_action_bt_node PROPERTIES PREFIX "")
# 新建目录,用于输出插件
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set_target_properties(initial_stage_action_bt_node PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# link dependencies as usual
# target_link_libraries(test_plugin_action ${behaviortree_cpp_LIBRARIES})
# 替代 target_link_libraries 和 include_directories
ament_target_dependencies(initial_stage_action_bt_node
    rclcpp 
    std_msgs 
    # Eigen3 
    ${behaviortree_cpp_LIBRARIES}
)





#打包配置插件
add_library(data_prerocess_action_bt_node SHARED plugins/action/data_prerocess_action.cpp )
list(APPEND plugin_libs data_prerocess_action_bt_node)

add_library(find_heel_strike_bt_node SHARED plugins/action/find_heel_strike.cpp  utils/load_data.cpp)
list(APPEND plugin_libs find_heel_strike_bt_node)

add_library(find_lr_zerocross_bt_node SHARED plugins/action/find_lr_zerocross.cpp )
list(APPEND plugin_libs find_lr_zerocross_bt_node)

add_library(find_toe_off_bt_node SHARED plugins/action/find_toe_off.cpp )
list(APPEND plugin_libs find_toe_off_bt_node)

# 新建目录,用于输出插件
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
foreach(bt_plugin ${plugin_libs})

  # 修改目标属性，将目标的PREFIX 属性设置为空字符串，即移除默认的库名前缀lib，remove the "lib" prefix. Name of the file will be test_plugin_action.so
  set_target_properties(${bt_plugin} PROPERTIES PREFIX "")
  set_target_properties(${bt_plugin} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

  ament_target_dependencies(${bt_plugin}
      rclcpp 
      std_msgs 
      # Eigen3 
      ${behaviortree_cpp_LIBRARIES}
  )
  target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
endforeach()





# 替代 target_link_libraries 和 include_directories
ament_target_dependencies(${PROJECT_NAME}
    rclcpp 
    std_msgs 
    # Eigen3 
)


# 包含头文件目录
target_include_directories(${PROJECT_NAME} PRIVATE
  ${behaviortree_cpp_INCLUDE_DIRS}
  # ${nav2_behavior_tree_INCLUDE_DIRS} # 添加Nav2行为树头文件路径
  # jsoncpp
)



target_link_libraries(${PROJECT_NAME} 
BT::behaviortree_cpp
  # ${nav2_behavior_tree_LIBRARIES}  # 链接Nav2行为树库?
  # ${rclcpp_LIBRARIES}             # ROS 2 C++客户端库
)


target_include_directories(timer_test PRIVATE
  ${behaviortree_cpp_INCLUDE_DIRS}
  # ${nav2_behavior_tree_INCLUDE_DIRS} # 添加Nav2行为树头文件路径
  # jsoncpp
)
target_link_libraries(timer_test
BT::behaviortree_cpp
  # ${nav2_behavior_tree_LIBRARIES}  # 链接Nav2行为树库?
  # ${rclcpp_LIBRARIES}             # ROS 2 C++客户端库
)